package p270jp.pxv.android.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import java.util.ArrayList;
import p014ae.AbstractActivityC0155s3;
import p014ae.C0147r4;
import p014ae.View$OnClickListenerC0046a;
import p014ae.View$OnClickListenerC0054c;
import p014ae.View$OnClickListenerC0133o8;
import p047bg.C1124a;
import p134ei.AnalyticsAction;
import p134ei.AnalyticsScreenName;
import p165fo.Subscribe;
import p187gl.C3360i;
import p187gl.C3366o;
import p210hh.PixivAccountManager;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.SearchFilterActivity;
import p270jp.pxv.android.legacy.constant.ContentType;
import p270jp.pxv.android.legacy.constant.SearchDuration;
import p270jp.pxv.android.legacy.constant.SearchTarget;
import p270jp.pxv.android.model.SearchBookmarkRange;
import p270jp.pxv.android.model.SearchBookmarkRangeListConverter;
import p270jp.pxv.android.model.SearchDurationListConverter;
import p270jp.pxv.android.model.SearchDurationParameter;
import p270jp.pxv.android.model.SearchDurationSetting;
import p270jp.pxv.android.model.SearchParameter;
import p270jp.pxv.android.model.SearchTargetListConverter;
import p270jp.pxv.android.model.SingleChoiceListValue;
import p314lg.ActivitySearchFilterBinding;
import p350mp.Timber;
import p370ni.InfoType;
import p416pb.ConstructorConstructor;
import p491sd.C6034a;
import p547uh.SingleChoiceDialogFragment;
import p569vd.C6830b;
import p593wc.Single;
import p645yc.AndroidSchedulers;
import p671zc.CompositeDisposable;

/* renamed from: jp.pxv.android.activity.SearchFilterActivity */
/* loaded from: classes2.dex */
public class SearchFilterActivity extends AbstractActivityC0155s3 {

    /* renamed from: k0 */
    public static final /* synthetic */ int f18654k0 = 0;

    /* renamed from: b0 */
    public ActivitySearchFilterBinding f18655b0;

    /* renamed from: c0 */
    public SearchTargetListConverter f18656c0;

    /* renamed from: d0 */
    public SearchDurationListConverter f18657d0;

    /* renamed from: e0 */
    public SearchBookmarkRangeListConverter f18658e0;

    /* renamed from: f0 */
    public SearchParameter f18659f0;

    /* renamed from: g0 */
    public SearchDurationParameter f18660g0;

    /* renamed from: h0 */
    public SearchBookmarkRange f18661h0;

    /* renamed from: i0 */
    public SearchTarget f18662i0;

    /* renamed from: j0 */
    public CompositeDisposable f18663j0 = new CompositeDisposable();

    /* renamed from: jp.pxv.android.activity.SearchFilterActivity$a */
    /* loaded from: classes2.dex */
    public static /* synthetic */ class C4114a {

        /* renamed from: a */
        public static final /* synthetic */ int[] f18664a;

        static {
            int[] iArr = new int[ContentType.values().length];
            f18664a = iArr;
            try {
                iArr[ContentType.ILLUST.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f18664a[ContentType.MANGA.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f18664a[ContentType.NOVEL.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    /* renamed from: e1 */
    public final void m4714e1() {
        Single pVar;
        if (!ConstructorConstructor.m3047b(this)) {
            this.f18655b0.f21990u.m4595d(InfoType.NETWORK_ERROR, new View$OnClickListenerC0054c(this, 7));
            return;
        }
        this.f18655b0.f21990u.m4595d(InfoType.LOADING, null);
        SearchParameter searchParameter = this.f18659f0;
        ContentType contentType = searchParameter.getContentType();
        if (contentType == ContentType.ILLUST) {
            pVar = PixivAccountManager.m5511e().m5513c().m970f(new C3366o(searchParameter, 1));
        } else if (contentType == ContentType.NOVEL) {
            pVar = PixivAccountManager.m5511e().m5513c().m970f(new C3360i(searchParameter, 1));
        } else {
            throw new IllegalArgumentException();
        }
        this.f18663j0.mo82c(pVar.m961o(C6034a.f26178c).m966j(AndroidSchedulers.m334a()).m963m(new C6830b(this, 5), new C0147r4(this, 3)));
    }

    /* renamed from: f1 */
    public final void m4713f1(SearchDurationParameter searchDurationParameter) {
        this.f18655b0.f21989t.setText(this.f18657d0.createItemLabel(searchDurationParameter));
    }

    /* renamed from: g1 */
    public final void m4712g1() {
        this.f18655b0.f21988s.setText(this.f18658e0.createItemLabel(this.f18661h0));
        this.f18655b0.f21992w.setOnClickListener(new View$OnClickListenerC0133o8(this, 0));
    }

    /* renamed from: h1 */
    public final void m4711h1(int i, ArrayList<SingleChoiceListValue> arrayList, int i2, int i3) {
        SingleChoiceDialogFragment.m1440f(i, arrayList, i2, i3).show(m11131K0(), "search_filter_setting_dialog");
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 1 && i2 == -1) {
            SearchDurationParameter createCustomParameter = SearchDurationParameter.createCustomParameter((SearchDurationSetting) intent.getSerializableExtra("RESULT_KEY_DURATION_SETTING"));
            this.f18660g0 = createCustomParameter;
            m4713f1(createCustomParameter);
        }
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ActivitySearchFilterBinding n1Var = (ActivitySearchFilterBinding) DataBindingUtil.m11369d(this, R.layout.activity_search_filter);
        this.f18655b0 = n1Var;
        C1124a.m10197Q(this, n1Var.f21985A, R.string.search_filter);
        SearchParameter searchParameter = (SearchParameter) getIntent().getSerializableExtra("SEARCH_PARAM");
        this.f18659f0 = searchParameter;
        int i = C4114a.f18664a[searchParameter.getContentType().ordinal()];
        if (i == 1 || i == 2) {
            this.f18757A.m6525e(AnalyticsScreenName.SEARCH_FILTER_ILLUST_MANGA);
        } else if (i == 3) {
            this.f18757A.m6525e(AnalyticsScreenName.SEARCH_FILTER_NOVEL);
        }
        this.f18656c0 = new SearchTargetListConverter(this, SearchTarget.Companion.getValuesByContentType(this.f18659f0.getContentType()));
        this.f18657d0 = new SearchDurationListConverter(this);
        SearchTarget target = this.f18659f0.getTarget();
        this.f18662i0 = target;
        this.f18655b0.f21987r.setText(target.getTitle(this));
        this.f18655b0.f21994y.setOnClickListener(new View$OnClickListenerC0046a(this, 6));
        SearchDurationParameter durationParameter = this.f18659f0.getDurationParameter();
        this.f18660g0 = durationParameter;
        this.f18655b0.f21989t.setText(this.f18657d0.createItemLabel(durationParameter));
        this.f18655b0.f21993x.setOnClickListener(new View.OnClickListener(this, 1) { // from class: ae.n8

            /* renamed from: a */
            public final /* synthetic */ int f502a;

            /* renamed from: b */
            public final /* synthetic */ SearchFilterActivity f503b;

            {
                this.f502a = r2;
                this.f503b = r1;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                switch (this.f502a) {
                    case 0:
                        SearchFilterActivity searchFilterActivity = this.f503b;
                        int i2 = SearchFilterActivity.C4114a.f18664a[searchFilterActivity.f18659f0.getContentType().ordinal()];
                        if (i2 == 1 || i2 == 2) {
                            searchFilterActivity.f18757A.m6528b(4, AnalyticsAction.SEARCH_FILTER_ILLUST_MANGA);
                        } else if (i2 == 3) {
                            searchFilterActivity.f18757A.m6528b(4, AnalyticsAction.SEARCH_FILTER_NOVEL);
                        }
                        Intent intent = new Intent();
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_TARGET", searchFilterActivity.f18662i0);
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_DURATION", searchFilterActivity.f18660g0);
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_BOOKMARK_RANGE", searchFilterActivity.f18661h0);
                        searchFilterActivity.setResult(-1, intent);
                        searchFilterActivity.finish();
                        return;
                    default:
                        SearchFilterActivity searchFilterActivity2 = this.f503b;
                        searchFilterActivity2.m4711h1(R.string.search_duration, searchFilterActivity2.f18657d0.createSingleChoiceListValues(searchFilterActivity2.f18660g0), searchFilterActivity2.f18657d0.getIndex(searchFilterActivity2.f18660g0.getSearchDuration()), 1);
                        return;
                }
            }
        });
        this.f18661h0 = this.f18659f0.getBookmarkRange();
        if (PixivAccountManager.m5511e().f16503i) {
            m4714e1();
        } else {
            ArrayList arrayList = new ArrayList();
            arrayList.add(SearchBookmarkRange.Companion.createDefaultInstance());
            this.f18658e0 = new SearchBookmarkRangeListConverter(this, arrayList);
            m4712g1();
        }
        if (PixivAccountManager.m5511e().f16503i) {
            this.f18655b0.f21995z.setCompoundDrawablesWithIntrinsicBounds((Drawable) null, (Drawable) null, (Drawable) null, (Drawable) null);
        }
        this.f18655b0.f21991v.setOnClickListener(new View.OnClickListener(this, 0) { // from class: ae.n8

            /* renamed from: a */
            public final /* synthetic */ int f502a;

            /* renamed from: b */
            public final /* synthetic */ SearchFilterActivity f503b;

            {
                this.f502a = r2;
                this.f503b = r1;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                switch (this.f502a) {
                    case 0:
                        SearchFilterActivity searchFilterActivity = this.f503b;
                        int i2 = SearchFilterActivity.C4114a.f18664a[searchFilterActivity.f18659f0.getContentType().ordinal()];
                        if (i2 == 1 || i2 == 2) {
                            searchFilterActivity.f18757A.m6528b(4, AnalyticsAction.SEARCH_FILTER_ILLUST_MANGA);
                        } else if (i2 == 3) {
                            searchFilterActivity.f18757A.m6528b(4, AnalyticsAction.SEARCH_FILTER_NOVEL);
                        }
                        Intent intent = new Intent();
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_TARGET", searchFilterActivity.f18662i0);
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_DURATION", searchFilterActivity.f18660g0);
                        intent.putExtra("RESULT_BUNDLE_KEY_FILTER_BOOKMARK_RANGE", searchFilterActivity.f18661h0);
                        searchFilterActivity.setResult(-1, intent);
                        searchFilterActivity.finish();
                        return;
                    default:
                        SearchFilterActivity searchFilterActivity2 = this.f503b;
                        searchFilterActivity2.m4711h1(R.string.search_duration, searchFilterActivity2.f18657d0.createSingleChoiceListValues(searchFilterActivity2.f18660g0), searchFilterActivity2.f18657d0.getIndex(searchFilterActivity2.f18660g0.getSearchDuration()), 1);
                        return;
                }
            }
        });
    }

    @Override // p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        this.f18663j0.m80f();
    }

    @Subscribe
    public void onEvent(SingleChoiceDialogFragment.C6603a aVar) {
        int i = aVar.f28159a;
        if (i == 1) {
            SearchDuration searchDuration = SearchDuration.values()[aVar.f28160b];
            if (searchDuration == SearchDuration.SELECT) {
                startActivityForResult(new Intent(this, SearchDurationCustomActivity.class), 1);
            } else if (searchDuration != SearchDuration.CUSTOM_DURATION) {
                SearchDurationParameter createNormalParameter = SearchDurationParameter.createNormalParameter(searchDuration);
                this.f18660g0 = createNormalParameter;
                m4713f1(createNormalParameter);
            }
        } else if (i == 2) {
            SearchBookmarkRange searchBookmarkRangeByIndex = this.f18658e0.getSearchBookmarkRangeByIndex(aVar.f28160b);
            this.f18661h0 = searchBookmarkRangeByIndex;
            this.f18655b0.f21988s.setText(this.f18658e0.createItemLabel(searchBookmarkRangeByIndex));
        } else if (i == 3) {
            SearchTarget item = this.f18656c0.getItem(aVar.f28160b);
            this.f18662i0 = item;
            this.f18655b0.f21987r.setText(item.getTitle(this));
        } else {
            Timber.f23100a.mo3515o("Receive unintended request code: %s", Integer.valueOf(i));
        }
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        finish();
        return true;
    }
}
